package cn.yunhe.service.impl;

import cn.yunhe.dao.TopicMapper;
import cn.yunhe.entity.Page;
import cn.yunhe.entity.Topic;
import cn.yunhe.service.ITopicService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Getter
@Setter
@Service
public class TopicService implements ITopicService {

    @Autowired
    private TopicMapper topicMapper;

    @Override
    public Page queryTopicByPage(Map<String, Object> cond) {
        Page page = new Page();
        //获取每页显示的条数
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        //获取当前页数
        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setCurPageNum(curPageNum);
        //动态计算总页数
        page.setTotalPages(page.getTotalNum() / pageSize + (page.getTotalNum() % pageSize == 0 ? 0 : 1));
        //根据页面条件获取总条数
        page.setTotalNum(topicMapper.getLikeTopicCount(cond));
        //获取处理结果
        page.setResult(topicMapper.getLikeTopic(cond));
        return page;
    }
}
